<?php

namespace common\models;

use Yii;
use yii\helpers\ArrayHelper;

/**
 * This is the model class for table "{{%article_category}}".
 *
 * @property string $id
 * @property string $name 文章名称
 * @property string $notice 备注
 * @property int $created_at 创建时间
 * @property int $updated_at 更新时间
 */
class ArticleCategory extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%article_category}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['name'], 'required'],
            [['created_at', 'updated_at'], 'integer'],
            [['name', 'notice'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => '编号',
            'name' => '分类名称',
            'notice' => '备注',
            'created_at' => '创建时间',
            'updated_at' => '更新时间',
        ];
    }

    /**
     * 获取类别的下拉菜单
     * @return array
     */
    public static function dropDown()
    {
        $data = self::find()->asArray()->all();
        $data_list = ArrayHelper::map($data, 'id', 'name');
        return $data_list;
    }

    /**
     * 获取类别的下拉菜单 包括全部选项 用于搜索头部
     * @return array
     */
    public static function dropDownAll()
    {
        $drop_list = self::dropDown();
        $drop_list[''] = '全部文章';
        ksort($drop_list);
        return $drop_list;
    }
}
